package com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.view;

import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.base.BaseActivity;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.bean.DevicesCustomConfigurationBean;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.fragment.Fragment_persenter.MouseSetPersenter;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.fragment.fragment_contract.IMouseSetContract;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.utils.MyToastUtils;

/**
 * Created by Administrator on 2018/8/14.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class MouseSetActivity  extends BaseActivity implements IMouseSetContract.IMouseSetView,View.OnClickListener {
    private MouseSetPersenter mMouseSetPersenter = new MouseSetPersenter(this);
    private RelativeLayout rl_user_name;
    private TextView tv_name;
    private RelativeLayout rl_panith;
    private TextView tv_panith_size;
    private RelativeLayout rl_panith_color;
    private TextView tv_panith_color;
    private RelativeLayout rl_cursor_color;
    private TextView tv_cursor_color;
    private ImageView iv_is_disable_return;
    private DevicesCustomConfigurationBean.DeviceMousesBean bean;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what == 1){
              if(return_change_name != null && !TextUtils.isEmpty(return_change_name)){
                  setUserName(return_change_name);
                  // 保存date
                  if(bean != null){
                      bean.setName(return_change_name);
                  }
              }

            }
        }
    };
    private String return_change_name;
    private int postion;
    private String devicesAttrId;

    @Override
    protected void userAgreedPermissions() {

    }

    @Override
    protected View AddLayoutView() {
        View view  =View.inflate(this, R.layout.activity_mouse_set,null);
        rl_user_name = view.findViewById(R.id.activity_mouse_set_rl_user_name);
        tv_name = view.findViewById(R.id.activity_mouse_set_tv_name);

        rl_panith = view.findViewById(R.id.activity_mouse_set_rl_panith);
        tv_panith_size = view.findViewById(R.id.activity_mouse_set_tv_panith_size);

        rl_panith_color = view.findViewById(R.id.activity_mouse_set_rl_panith_color);
        tv_panith_color = view.findViewById(R.id.activity_mouse_set_tv_panith_color);

        rl_cursor_color = view.findViewById(R.id.activity_mouse_set_rl_cursor_color);
        tv_cursor_color = view.findViewById(R.id.activity_mouse_set_tv_cursor_color);

        iv_is_disable_return = view.findViewById(R.id.activity_mouse_set_iv_is_disable_return);
        return view;
    }

    @Override
    protected void initChildViewDate() {
       Intent intent =  getIntent();
        bean = (DevicesCustomConfigurationBean.DeviceMousesBean) intent.getSerializableExtra("file_set_config_to_mouse_set");
        postion = intent.getIntExtra("file_mouse_set_selelctor_postion",0);
        devicesAttrId = intent.getStringExtra("file_mouse_devicesAttrId");
        mMouseSetPersenter.initTitle();
        rl_user_name.setOnClickListener(this);
        rl_panith.setOnClickListener(this);
        rl_panith_color.setOnClickListener(this);
        rl_cursor_color.setOnClickListener(this);
        iv_is_disable_return.setOnClickListener(this);
        mMouseSetPersenter.initDate(this,bean);
    }

    @Override
    protected void onClickedTvRight() {
        mMouseSetPersenter.saveDate(this,bean,postion,devicesAttrId);
    }

    @Override
    protected void onClickedIvRight() {

    }

    @Override
    protected void onClickedIvLeft() {

    }

    @Override
    public void showTitle() {
        showTilteBg();
        showTitleContent();
        showTileIvLeft();
        showTilteRightTVContent();
        //设备管理(6)
        setTitleContent("1号鼠标", 0xffffffff);
        setTilteRightTVContent("保存",0xffffffff);
        setIvLeftIcon(R.mipmap.left_white_return);
    }

    @Override
    public String getUserName() {
        return tv_name.getText().toString().trim();
    }

    @Override
    public void setUserName(String name) {
        tv_name.setText(name);
    }

    @Override
    public String getBrushSize() {
        return tv_panith_size.getText().toString().trim();
    }

    @Override
    public void setBrushSize(String size) {
        tv_panith_size.setText(size);
    }

    @Override
    public String getBrushColor() {
        return "#ff00ff";
    }

    @Override
    public void setBrushColor(String color) {
        tv_panith_color.setBackgroundColor(Color.parseColor(color));
    }

    @Override
    public String getCursorColor() {
        return tv_cursor_color.getText().toString().trim();

    }

    @Override
    public void setCursorColor(String color) {
        tv_cursor_color.setText(color);
    }

    @Override
    public void showDisable() {
        iv_is_disable_return.setImageResource(R.mipmap.personal_open);
    }

    @Override
    public void hidenDisable() {
        iv_is_disable_return.setImageResource(R.mipmap.personal_close);
    }

    @Override
    public void toChangeName() {
        //toPageJump(ChangeMettingNameActivity.class);
        Intent  intent = new Intent(this,ChangeMettingNameActivity.class);
        intent.putExtra("change_name_pager",1);
        startActivityForResult(intent,1);
    }

    @Override
    public void showToastMassage(String message) {
        MyToastUtils.ShortToaseShow(this,message);
    }

    @Override
    public void tofinshPager() {
        finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.activity_mouse_set_rl_user_name:
                mMouseSetPersenter.onCkleckUserName();  //ChangeMettingNameActivity
                break;
            case R.id.activity_mouse_set_rl_panith:
                mMouseSetPersenter.onCkicledBrushSize(this);
                break;
            case R.id.activity_mouse_set_rl_panith_color:
                mMouseSetPersenter.onCkicledBrushColor();
                break;
            case R.id.activity_mouse_set_rl_cursor_color:
                mMouseSetPersenter.onClickedCursorColor(this);
                break;
            case R.id.activity_mouse_set_iv_is_disable_return:
                mMouseSetPersenter.isDisable();
                break;

        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      //  super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == 1){
            return_change_name = data.getStringExtra("return_change_name");
            if(return_change_name != null && !TextUtils.isEmpty(return_change_name)){
                Message msg =  Message.obtain();
                msg.what =1;
                handler.sendMessage(msg);
            }
        }
    }
}
